<?php
include_once("config.php");
checkLoggedIn("no");

if(isset($_POST["submit"])) 
{
	field_validator("login name", $_POST["login"], "alphanumeric", 1, 15);
	field_validator("password", $_POST["password"], "string", 4, 15);
	if($messages)
	{
		doIndex();
		exit;
	}
    	if( !($row = checkPass($_POST["login"], $_POST["password"])) ) 
	{
        	$messages[]="Incorrect login/password, try again";
    	}
	if($messages)
	{
		doIndex();
		exit;
	}
	cleanMemberSession($_POST["login"], $_POST["password"]);
	header("Location: members.php");
} 
else 
{
	doIndex();
}

function doIndex() 
{
	global $messages;
	global $title;
?>
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php print $title; ?></title>
</head>
<style type="text/css">
<!--
@import url("style.css");
-->
</style>
</head>


<?php doCSS(); ?>
<body>
<center>
<h1> Paquetesystem - Sistema de Tracking </h1>
<br>
<img src="index.jpg"  align="middle">
<br><br><br>

<?php
if($messages) { displayErrors($messages); }

?>
<form action="<?php print $_SERVER["PHP_SELF"]; ?>" method="POST">
<table>
<tr><td>Usuario:</td><td><input type="text" name="login"
value="<?php print isset($_POST["login"]) ? $_POST["login"] : "" ; ?>"
maxlength="15"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" value="" maxlength="15"></td></tr>
<tr><td>&nbsp;</td><td><input name="submit" type="submit" value="Submit"></td></tr>
<tr><td><a href="n_usuario.php">Nuevo usuario?</a></td></tr>
</table>
</form>
</pre>
</center>
</body>
</html>
<?php
}
?>
